﻿<cfscript>
/** 
* ORM Questionnaire
* 
* @hint "Hibernate persistenter t_questionnaire. 调查问卷" 
* 
*/ 

component 
	displayname="public.service.orm.senate.Questionnaire" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="Questionnaire" 
	table="t_questionnaire"
	{
	
	property type="string" name="QueID" column="qsn_id" fieldtype="id" generator="assigned" hint="问卷编号";

	property type="string" name="DateStart" column="date_start" hint="指定问卷开始日期";
	property type="string" name="DateEnd" column="date_end" hint="指定问卷结束日期";

	property type="string" name="Title" column="title" hint="问卷标题";
	property type="string" name="Describe" column="describe" hint="问卷说明";

	property type="string" name="GradesAllowed" column="grade_allowed" hint="参与调查年级";
	property type="string" name="InstituteAllowed" column="institute_allowed" hint="参与调查学院";
	property type="string" name="GenderAllowed" column="gender_allowed" hint="参与调查性别";
	
	property type="string" name="State" column="state" hint="问卷状态";
	
	property name="Creator" fieldtype="many-to-one" fkcolumn="tch_id" cfc="Teacher"  hint="问卷创建者";
	
	property name="QuestionQuotas" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="qsn_id" cfc="QuestionQuota" hint="问卷的内置指标";	
	property name="QuestionRespondents" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="qsn_id" cfc="QuestionRespondent" hint="调查问卷预设允许答题学生范围";	
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		var nextID = year(now()) & numberFormat(1, "0___");
		
		var checkArray = ORMExecuteQuery("select QueID from Questionnaire 
											where QueID like :condition 
											order by QueID desc", { condition = year(now()) & "____" }, { maxResults=1 });
		
		/* 
			主键生成规则 
			
			4位年份 + 4位流水号
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = year(now()) & numberFormat((right(checkArray[1], 4) + 1), "0___");
			
		}

		return nextID;
	}
	
}

</cfscript>